package com.health.healthSys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.health.common.core.domain.entity.SysUser;
import com.health.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.health.common.annotation.Log;
import com.health.common.core.controller.BaseController;
import com.health.common.core.domain.AjaxResult;
import com.health.common.enums.BusinessType;
import com.health.healthSys.domain.HealthInfo;
import com.health.healthSys.service.IHealthInfoService;
import com.health.common.utils.poi.ExcelUtil;
import com.health.common.core.page.TableDataInfo;

/**
 * 资讯管理Controller
 *
 * @author maple
 * @date 2025-03-01
 */
@RestController
@RequestMapping("/healthSys/info")
public class HealthInfoController extends BaseController
{
    @Autowired
    private IHealthInfoService healthInfoService;
    @Autowired
    private ISysUserService sysUserService;
    /**
     * 查询资讯管理列表
     */
    @PreAuthorize("@ss.hasPermi('healthSys:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(HealthInfo healthInfo)
    {
        startPage();
        List<HealthInfo> list = healthInfoService.selectHealthInfoList(healthInfo);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('healthSys:info:list')")
    @GetMapping("/healthList")
    public TableDataInfo healthList(HealthInfo healthInfo)
    {
        startPage();
        List<HealthInfo> list = healthInfoService.selectHealthInfoHealthList(healthInfo);
        return getDataTable(list);
    }
    /**
     * 导出资讯管理列表
     */
/*    @PreAuthorize("@ss.hasPermi('healthSys:info:export')")
    @Log(title = "资讯管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HealthInfo healthInfo)
    {
        List<HealthInfo> list = healthInfoService.selectHealthInfoList(healthInfo);
        ExcelUtil<HealthInfo> util = new ExcelUtil<HealthInfo>(HealthInfo.class);
        util.exportExcel(response, list, "资讯管理数据");
    }*/

    /**
     * 获取资讯管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('healthSys:info:query')")
    @GetMapping(value = "/{infoId}")
    public AjaxResult getInfo(@PathVariable("infoId") String infoId)
    {
        return success(healthInfoService.selectHealthInfoByInfoId(infoId));
    }

    /**
     * 新增资讯管理
     */
    @PreAuthorize("@ss.hasPermi('healthSys:info:add')")
    @Log(title = "资讯管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HealthInfo healthInfo)
    {
        healthInfo.setUserId(getUserId());
        return toAjax(healthInfoService.insertHealthInfo(healthInfo));
    }

    /**
     * 修改资讯管理
     */
    @PreAuthorize("@ss.hasPermi('healthSys:info:edit')")
    @Log(title = "资讯管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HealthInfo healthInfo)
    {
        return toAjax(healthInfoService.updateHealthInfo(healthInfo));
    }

    /**
     * 删除资讯管理
     */
    @PreAuthorize("@ss.hasPermi('healthSys:info:remove')")
    @Log(title = "资讯管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{infoIds}")
    public AjaxResult remove(@PathVariable String[] infoIds)
    {
        return toAjax(healthInfoService.deleteHealthInfoByInfoIds(infoIds));
    }

}
